<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        function foo() {
            let args = Array.prototype.slice.call(arguments);
            let _foo = function() {
                args.push(...Array.prototype.slice.call(arguments));
                return _foo;
            };
            _foo.toString = function() {
                const total = args.reduce((i, num) => {
                    return i + num;
                }, 0);
                return total
            };
            return _foo;
        }

        const num1 = foo(1)(2)(3)(4);
        const num2 = foo(1, 2, 4)(3);

        console.log(num1);
        console.log(num2 == 10);
    </script>
</body>

</html>